/*
 * JPnuevacuentabanco.java
 *
 * Created on 14 de mayo de 2007, 01:14 AM
 */

package pantalla;

import java.sql.*;
import utiles.*;
import java.util.ArrayList;
import java.rmi.*;
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
/**
 *
 * @author  casa
 */
public class JPnuevacuentabanco extends javax.swing.JPanel {
    boolean aparece=true;
     ResultSet cuentas;
    funcioncliente.FuncionesControlAcceso fca;
    javax.swing.JInternalFrame jif;
    String nombre_trabajador,dni,conecta[],tiposmon[],bancos[];
    
     int tiposcu[];
     java.awt.Point punto;
    String identificador;
     int num_sul,posSelCod;
    Utiles_Busqueda popbuscador;
    
    
    /** Creates new form JPnuevacuentabanco */
    public JPnuevacuentabanco(String [] cone,String id) {
        initComponents();
        jrbCodigo.setMnemonic(java.awt.event.KeyEvent.VK_O);
        jrbNombre.setMnemonic(java.awt.event.KeyEvent.VK_M);
        jbGuardar.setMnemonic(java.awt.event.KeyEvent.VK_G);
        jbSalir.setMnemonic(java.awt.event.KeyEvent.VK_S);
        jbBuscar.setMnemonic(java.awt.event.KeyEvent.VK_B);
        jbCancelar.setMnemonic(java.awt.event.KeyEvent.VK_L);
       identificador=id;
        
        
         if (System.getSecurityManager() == null){
 		System.setSecurityManager(new RMISecurityManager());
 		}
        
        try{
			fca=(funcioncliente.FuncionesControlAcceso)java.rmi.Naming.lookup("//"+cone[0]+":"+cone[1]+"/"+cone[2]);
                        
                        }catch(Exception g){
				mensaje("Problemas conectando "+g.toString());
                                g.printStackTrace();
                            
		}
   
        conecta=cone;
        punto=jtfCodigo.getLocation();
    
         String consultatt = "select p.codigo_persona, p.nombre, p.Ap_paterno, " +
                    "p.Ap_materno,' - DNI: '+p.codigo_persona from Persona p, Trabajador t where p.codigo_persona = t.dni";                
        int[] coltt = { 3, 4, 2,5 };
        popbuscador =new Utiles_Busqueda( this.jpmNombres, this.jtfCodigo, consultatt, coltt, ConsultasCliRmi.clirmi,punto.x+140,punto.y-2,identificador );
        
        cargar_combos();
        jtCuentas.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
    }
    
    
    public  void ponerancestro(javax.swing.JInternalFrame jjj){
        jif=jjj;
    }
     
    public   void mensaje(String mens){
         javax.swing.JOptionPane.showMessageDialog( this,mens,
      "Mensaje de Informacion",javax.swing.JOptionPane.ERROR_MESSAGE);
    }
      
    public   void cerrar(){
          int res = javax.swing.JOptionPane.showConfirmDialog( this,"Esta seguro de salir?",
      "Confirmar",javax.swing.JOptionPane.YES_NO_OPTION );
         if(res==javax.swing.JOptionPane.YES_OPTION){
                  fca=null;
                  jif.dispose();
         }
      }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jpmNombres = new javax.swing.JPopupMenu();
        jrbCodigo = new javax.swing.JRadioButton();
        jrbNombre = new javax.swing.JRadioButton();
        jtfCodigo = new javax.swing.JTextField();
        jbBuscar = new javax.swing.JButton();
        jlTraba = new javax.swing.JLabel();
        jlTrabajador = new javax.swing.JLabel();
        jlBanco = new javax.swing.JLabel();
        jcboBanco = new javax.swing.JComboBox();
        jlNumCuenta = new javax.swing.JLabel();
        jtfNumCuenta = new javax.swing.JTextField();
        jlTipoCuenta = new javax.swing.JLabel();
        jlTipoMoneda = new javax.swing.JLabel();
        jcboTipoMoneda = new javax.swing.JComboBox();
        jcboTipoCuenta = new javax.swing.JComboBox();
        jbGuardar = new javax.swing.JButton();
        jbCancelar = new javax.swing.JButton();
        jbSalir = new javax.swing.JButton();
        jchkCts = new javax.swing.JCheckBox();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtCuentas = new javax.swing.JTable();
        jbImprimir = new javax.swing.JButton();
        jbEliminar = new javax.swing.JButton();

        buttonGroup1.add(jrbCodigo);
        jrbCodigo.setFont(new java.awt.Font("Arial", 0, 12));
        jrbCodigo.setSelected(true);
        jrbCodigo.setText("Codigo trabajador");
        jrbCodigo.setToolTipText("buscar por codigo");
        jrbCodigo.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jrbCodigo.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jrbCodigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbCodigoActionPerformed(evt);
            }
        });
        jrbCodigo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jrbCodigoKeyPressed(evt);
            }
        });

        buttonGroup1.add(jrbNombre);
        jrbNombre.setFont(new java.awt.Font("Arial", 0, 12));
        jrbNombre.setText("Nombre trabajador");
        jrbNombre.setToolTipText("buscar por nombre");
        jrbNombre.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jrbNombre.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jrbNombre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbNombreActionPerformed(evt);
            }
        });
        jrbNombre.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jrbNombreKeyPressed(evt);
            }
        });

        jtfCodigo.setFont(new java.awt.Font("Arial", 0, 12));
        jtfCodigo.setComponentPopupMenu(jpmNombres);
        jtfCodigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfCodigoActionPerformed(evt);
            }
        });
        jtfCodigo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtfCodigoKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jtfCodigoKeyReleased(evt);
            }
        });

        jbBuscar.setFont(new java.awt.Font("Arial", 0, 12));
        jbBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/fife/plaf/Office2003/find.gif"))); // NOI18N
        jbBuscar.setText("Buscar");
        jbBuscar.setToolTipText("busqueda");
        jbBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbBuscarActionPerformed(evt);
            }
        });

        jlTraba.setFont(new java.awt.Font("Arial", 0, 12));
        jlTraba.setText("Trabajador");

        jlTrabajador.setFont(new java.awt.Font("Arial", 0, 12));
        jlTrabajador.setToolTipText("trabajador buscado");

        jlBanco.setFont(new java.awt.Font("Arial", 0, 12));
        jlBanco.setText("Banco");

        jcboBanco.setFont(new java.awt.Font("Arial", 0, 12));
        jcboBanco.setToolTipText("bancos");
        jcboBanco.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcboBancoActionPerformed(evt);
            }
        });
        jcboBanco.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcboBancoKeyPressed(evt);
            }
        });

        jlNumCuenta.setFont(new java.awt.Font("Arial", 0, 12));
        jlNumCuenta.setText("Num.Cuenta");

        jtfNumCuenta.setFont(new java.awt.Font("Arial", 0, 12));
        jtfNumCuenta.setToolTipText("numero de cuenta bancaria");
        jtfNumCuenta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfNumCuentaActionPerformed(evt);
            }
        });

        jlTipoCuenta.setFont(new java.awt.Font("Arial", 0, 12));
        jlTipoCuenta.setText("Tipo Cuenta");

        jlTipoMoneda.setFont(new java.awt.Font("Arial", 0, 12));
        jlTipoMoneda.setText("Tipo Moneda");

        jcboTipoMoneda.setFont(new java.awt.Font("Arial", 0, 12));
        jcboTipoMoneda.setToolTipText("Tipos de moneda de cuentas");
        jcboTipoMoneda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcboTipoMonedaActionPerformed(evt);
            }
        });
        jcboTipoMoneda.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcboTipoMonedaKeyPressed(evt);
            }
        });

        jcboTipoCuenta.setFont(new java.awt.Font("Arial", 0, 12));
        jcboTipoCuenta.setToolTipText("tipos de cuentas bancarias");
        jcboTipoCuenta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcboTipoCuentaActionPerformed(evt);
            }
        });
        jcboTipoCuenta.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcboTipoCuentaKeyPressed(evt);
            }
        });

        jbGuardar.setFont(new java.awt.Font("Arial", 0, 12));
        jbGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/fife/plaf/Office2003/save.gif"))); // NOI18N
        jbGuardar.setText("Guardar");
        jbGuardar.setToolTipText("guardar cuenta");
        jbGuardar.setEnabled(false);
        jbGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbGuardarActionPerformed(evt);
            }
        });

        jbCancelar.setFont(new java.awt.Font("Arial", 0, 12));
        jbCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/fife/plaf/Office2003/new.gif"))); // NOI18N
        jbCancelar.setText("Limpiar");
        jbCancelar.setToolTipText("cancelar operacion");
        jbCancelar.setEnabled(false);
        jbCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbCancelarActionPerformed(evt);
            }
        });

        jbSalir.setFont(new java.awt.Font("Arial", 0, 12));
        jbSalir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/fife/plaf/Office2003/close.gif"))); // NOI18N
        jbSalir.setText("Salir");
        jbSalir.setToolTipText("salir");
        jbSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbSalirActionPerformed(evt);
            }
        });

        jchkCts.setFont(new java.awt.Font("Arial", 0, 12));
        jchkCts.setText("Cuenta CTS");
        jchkCts.setToolTipText("es cuenta de CTS");
        jchkCts.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jchkCts.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jchkCts.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jchkCtsActionPerformed(evt);
            }
        });
        jchkCts.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jchkCtsKeyPressed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Cuentas del Trabajador", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N
        jPanel1.setFont(new java.awt.Font("Arial", 0, 12));

        jScrollPane1.setFont(new java.awt.Font("Arial", 0, 12));

        jtCuentas.setFont(new java.awt.Font("Arial", 0, 16)); // NOI18N
        jtCuentas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Num.Cuenta", "Banco", "Tipo Moneda", "Tipo Cuenta", "CTS"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                true, true, true, false, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jtCuentas);

        jbImprimir.setFont(new java.awt.Font("Arial", 0, 12));
        jbImprimir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/fife/plaf/Office2003/print.gif"))); // NOI18N
        jbImprimir.setText("Imprimir");
        jbImprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbImprimirActionPerformed(evt);
            }
        });
        jbImprimir.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbImprimirKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(474, Short.MAX_VALUE)
                .addComponent(jbImprimir)
                .addContainerGap())
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 585, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jbImprimir)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE))
        );

        jbEliminar.setFont(new java.awt.Font("Arial", 0, 12));
        jbEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/fife/plaf/Office2003/delete.gif"))); // NOI18N
        jbEliminar.setText("Eliminar");
        jbEliminar.setEnabled(false);
        jbEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbEliminarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jrbCodigo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtfCodigo, javax.swing.GroupLayout.DEFAULT_SIZE, 367, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbBuscar))
                    .addComponent(jrbNombre)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jlTraba)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jlTrabajador, javax.swing.GroupLayout.DEFAULT_SIZE, 426, Short.MAX_VALUE)
                        .addGap(105, 105, 105))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jbEliminar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbSalir))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jbGuardar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbCancelar))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jchkCts)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jlTipoMoneda)
                                    .addComponent(jlTipoCuenta))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jcboTipoMoneda, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jcboTipoCuenta, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jlNumCuenta)
                                    .addComponent(jlBanco))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jcboBanco, 0, 418, Short.MAX_VALUE)
                                    .addComponent(jtfNumCuenta, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(105, 105, 105)))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jbBuscar, jbCancelar, jbEliminar, jbGuardar, jbSalir});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jrbCodigo)
                    .addComponent(jbBuscar)
                    .addComponent(jtfCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jrbNombre)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlTraba)
                    .addComponent(jlTrabajador, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jlNumCuenta)
                        .addComponent(jtfNumCuenta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jlBanco)
                            .addComponent(jcboBanco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(35, 35, 35)))
                .addGap(14, 14, 14)
                .addComponent(jchkCts)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlTipoMoneda)
                    .addComponent(jcboTipoMoneda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlTipoCuenta)
                    .addComponent(jcboTipoCuenta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbGuardar)
                    .addComponent(jbCancelar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbSalir)
                    .addComponent(jbEliminar))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jbImprimirKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbImprimirKeyPressed
// TODO: Agrege su codigo aqui:
        if(evt.getKeyCode()==evt.VK_ENTER){
            jbImprimir.doClick();
        }
    }//GEN-LAST:event_jbImprimirKeyPressed

    private void jbImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbImprimirActionPerformed
// TODO add your handling code here:try{
        try{
            utiles.imprimir.tabla(jtCuentas,true,"Cuentas Bancarias del trabajador "+jlTrabajador.getText().trim(),"");
            
        }catch(Exception e){
            mensaje("Error en la impresion\n"+e.toString());
        }
    }//GEN-LAST:event_jbImprimirActionPerformed

    private void jcboTipoCuentaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcboTipoCuentaKeyPressed
// TODO: Agrege su codigo aqui:
         
          if(evt.getKeyCode()==evt.VK_ENTER){
          jbGuardar.requestFocus();
        }
    }//GEN-LAST:event_jcboTipoCuentaKeyPressed

    private void jcboTipoMonedaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcboTipoMonedaKeyPressed
// TODO: Agrege su codigo aqui:
         
          if(evt.getKeyCode()==evt.VK_ENTER){
          jcboTipoCuenta.requestFocus();
        }
    }//GEN-LAST:event_jcboTipoMonedaKeyPressed

    private void jchkCtsKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jchkCtsKeyPressed
// TODO: Agrege su codigo aqui:
          
           if(evt.getKeyCode()==evt.VK_ENTER){
          jcboTipoMoneda.requestFocus();
        }
    }//GEN-LAST:event_jchkCtsKeyPressed

    private void jcboBancoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcboBancoKeyPressed
// TODO: Agrege su codigo aqui:
         if(evt.getKeyCode()==evt.VK_ENTER){
           jtfNumCuenta.requestFocus();
        }
         
    }//GEN-LAST:event_jcboBancoKeyPressed

    private void jrbNombreKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jrbNombreKeyPressed
// TODO: Agrege su codigo aqui:
         if(evt.getKeyCode()==evt.VK_ENTER){
            jtfCodigo.requestFocus();
        }
    }//GEN-LAST:event_jrbNombreKeyPressed

    private void jrbCodigoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jrbCodigoKeyPressed
// TODO: Agrege su codigo aqui:
         if(evt.getKeyCode()==evt.VK_ENTER){
            jtfCodigo.requestFocus();
        }
    }//GEN-LAST:event_jrbCodigoKeyPressed

    private void jtfCodigoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfCodigoKeyPressed
// TODO: Agrege su codigo aqui:
    }//GEN-LAST:event_jtfCodigoKeyPressed

    private void jrbCodigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbCodigoActionPerformed
// TODO add your handling code here:
        this.popbuscador.activarBusqueda(false);
    }//GEN-LAST:event_jrbCodigoActionPerformed

    private void jrbNombreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbNombreActionPerformed
// TODO add your handling code here:
       this.popbuscador.activarBusqueda(true);
    }//GEN-LAST:event_jrbNombreActionPerformed

    private void jcboTipoCuentaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcboTipoCuentaActionPerformed
// TODO add your handling code here:
       
    }//GEN-LAST:event_jcboTipoCuentaActionPerformed

    private void jcboTipoMonedaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcboTipoMonedaActionPerformed
// TODO add your handling code here:
       
    }//GEN-LAST:event_jcboTipoMonedaActionPerformed

    private void jchkCtsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jchkCtsActionPerformed
// TODO add your handling code here:
      
    }//GEN-LAST:event_jchkCtsActionPerformed

    private void jcboBancoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcboBancoActionPerformed
// TODO add your handling code here:
       
    }//GEN-LAST:event_jcboBancoActionPerformed

    private void jtfCodigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfCodigoActionPerformed
// TODO add your handling code here:
        if(this.popbuscador.getIndicadorBusqueda()){
        if(this.popbuscador.getHizoEnter())
        busquedatrabajador();
        }
        else{
            busquedatrabajador();
        }
         
    }//GEN-LAST:event_jtfCodigoActionPerformed

    private void jbGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbGuardarActionPerformed
// TODO add your handling code here:
        //System.out.println(bancos[JCBbanco.getSelectedIndex()]+"  "+tiposmon[JCBtipomoneda.getSelectedIndex()]);
         if(verifica_cuenta(jtfNumCuenta.getText().trim())){
            String ret[];
             try{
                ret=fca.llenarcuentabancaria(dni,jtfNumCuenta.getText().trim(),bancos[jcboBanco.getSelectedIndex()],
                        tiposmon[jcboTipoMoneda.getSelectedIndex()],
                tiposcu[jcboTipoCuenta.getSelectedIndex()],jchkCts.isSelected(),false,identificador);
               
               
                 int err=Integer.valueOf(ret[1]);
          if(!ret[0].equalsIgnoreCase("bien")){
               String bla;
               try{
                   
                   bla=utiles.imprimir.errorSQL(err);
               }catch(Exception e){
                   bla=ret[0];
                   System.out.println(e.toString());
               }
               mensaje("Hubo un error al guardar la cuenta\n"+bla);
            }else{
                     javax.swing.JOptionPane.showMessageDialog( this,"Cuenta Guardada con Exito",
                  "Informacion de la transaccion",javax.swing.JOptionPane.INFORMATION_MESSAGE); 
                     busquedatrabajador();
                    
                }
                   limpiar();
                 
                }catch(java.rmi.RemoteException e){
                mensaje("Error RMI");
                }
            }
    }//GEN-LAST:event_jbGuardarActionPerformed

    private void jtfCodigoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfCodigoKeyReleased
// TODO add your handling code here:
         
    }//GEN-LAST:event_jtfCodigoKeyReleased

      
    
      
    private void jbSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbSalirActionPerformed
// TODO add your handling code here:
        cerrar();
    }//GEN-LAST:event_jbSalirActionPerformed

    private void jtfNumCuentaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfNumCuentaActionPerformed
// TODO add your handling code here:
        if(verifica_cuenta(jtfNumCuenta.getText().trim())){
            jchkCts.requestFocus();
        }else{
            jtfNumCuenta.requestFocus();
        }
        
    }//GEN-LAST:event_jtfNumCuentaActionPerformed

    private void jbCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCancelarActionPerformed
// TODO add your handling code here:
        limpiar();
        
        
    }//GEN-LAST:event_jbCancelarActionPerformed
    
    void limpiar(){
        
        jtfNumCuenta.setText("");
        jcboBanco.setSelectedIndex(0);
        jcboTipoMoneda.setSelectedIndex(0);
        jcboTipoCuenta.setSelectedIndex(0);
        //JCBgenera.setSelected(false);
        jchkCts.setSelected(false);
    }
    

   boolean verifica_cuenta(String numcu){
        boolean retu=true;
        int a=0;
        ArrayList banco;
        banco=ConsultasCliRmi.consulta("select id_cuenta_bancaria from" +
                " cuenta_bancaria where id_cuenta_bancaria='"+numcu+"'",identificador);
        //conexion.consultar("select id_cuenta_bancaria from" +
          //      " cuenta_bancaria where id_cuenta_bancaria='"+numcu+"'");
      a=banco.size()-2;
      
        if(a>0){
            mensaje("El numero de cuenta bancaria ya existe");
            jtfNumCuenta.setText("");
            retu=false;
            
        }
        
        return retu;
    }
    void cargar_combos(){
        ArrayList banco,auxbanco;
        banco=ConsultasCliRmi.consulta("select id_banco,nom_banco from banco",identificador);
        //banco=conexion.consultar("select id_banco,nom_banco from banco");
      
       
        
        int a,b,c;
        try{
            
            a=banco.size()-2;
            bancos=new String[a];
          
             for(int i=0;i<a;i++){
                auxbanco=(ArrayList)banco.get(i);
                jcboBanco.addItem(auxbanco.get(1).toString());
                bancos[i]=auxbanco.get(0).toString();
                }
                jcboBanco.setSelectedIndex(0);
                 
                 banco=null;
                 auxbanco=null;
                banco=ConsultasCliRmi.consulta("select tipo_mon_corr,nom_moneda from tipo_moneda",identificador);
               
                b=banco.size()-2;
                tiposmon=new String[b];
                
            for(int j=0;j<b;j++){
                auxbanco=(ArrayList)banco.get(j);
                
                jcboTipoMoneda.addItem(auxbanco.get(1).toString());
                tiposmon[j]=auxbanco.get(0).toString();
                }
                jcboTipoMoneda.setSelectedIndex(0);
                
                banco=null;
                auxbanco=null;
                
                banco=ConsultasCliRmi.consulta("select corr_tipo_cta,nom_tipo_cta from tipo_cuenta",identificador);
               
                c=banco.size()-2;
                tiposcu=new int[c];
                
            for(int k=0;k<c;k++){
                auxbanco=(ArrayList)banco.get(k);
                jcboTipoCuenta.addItem(auxbanco.get(1).toString());
                tiposcu[k]=((Integer)auxbanco.get(0)).intValue();
                }  
                jcboTipoCuenta.setSelectedIndex(0);
               
                banco=null;
                auxbanco=null;
                
        }catch(Exception e){
        
        }
        
    }
    
   
    
    void fallo(){
        jbGuardar.setEnabled(false);
        jbCancelar.setEnabled(false);
    }
    void busquedatrabajador(){
         String nomaux="";
       if( this.jrbCodigo.isSelected() ){
            this.posSelCod = this.popbuscador.buscaClave( this.jtfCodigo.getText().trim() );
            ArrayList araux=ConsultasCliRmi.consulta("select  p.Ap_paterno +' '" +
                    "+ p.Ap_materno + ' '+ p.nombre from Persona p where p.codigo_persona = '"+this.jtfCodigo.getText().trim()+"'",identificador);
            nomaux=((ArrayList)araux.get(0)).get(0).toString();
           
        }else if( this.jrbNombre.isSelected() ){
            this.posSelCod = this.popbuscador.getIndice();
            nomaux=this.jtfCodigo.getText().trim();
        }
        
        if( ( this.posSelCod == -1 || !this.popbuscador.getHizoEnter() ) && !jrbCodigo.isSelected() ){
            Utiles_MensajesDialogo.mensajeAlerta( "No se encuenta el Trabajador" );
             jlTrabajador.setText("");
             jtCuentas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Num. Cuenta", "Banco", "Tipo Moneda", "Tipo Cuenta", "CTS"
            }
        ));
                limpiar();
                fallo();
            
        }else{
                dni=this.popbuscador.getSoloClave(posSelCod).toString().trim();
                jtCuentas.setModel(ConsultasCliRmi.llenatabla("select id_cuenta_bancaria as [Num. Cuenta],banco.nom_banco as [Banco]," +
                        "tipo_moneda.nom_moneda as [Tipo Moneda] ,tipo_cuenta.nom_tipo_cta as [Tipo Cuenta],flag_cts as [CTS] from " +
                        "cuenta_bancaria inner join banco on cuenta_bancaria.id_banco= banco.id_banco " +
                        "inner join tipo_moneda on cuenta_bancaria.tipo_mon_corr =tipo_moneda.tipo_mon_corr " +
                        "inner join tipo_cuenta on cuenta_bancaria.corr_tipo_cta= tipo_cuenta.corr_tipo_cta" +
                        " where DNI='"+dni+"'",identificador));
                jlTrabajador.setText(nomaux);
                jbGuardar.setEnabled(true);
                jbCancelar.setEnabled(true);
                this.jbEliminar.setEnabled(true);
                jcboBanco.requestFocus();
           
        }
        
      
    }
    private void jbBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbBuscarActionPerformed
// TODO add your handling code here:
        busquedatrabajador();
    }//GEN-LAST:event_jbBuscarActionPerformed

    private void jbEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbEliminarActionPerformed
        // TODO add your handling code here:
        int res = javax.swing.JOptionPane.showConfirmDialog( this,"Esta seguro de eliminar la cuenta?",
                "Confirmar",javax.swing.JOptionPane.YES_NO_OPTION );
        
        if(res==javax.swing.JOptionPane.YES_OPTION ){
            int a=jtCuentas.getSelectedRow();
            String cuenta_elimina=jtCuentas.getValueAt(a,0).toString().trim();
            
            try{
                String ret[]=fca.eliminacuentabancaria(cuenta_elimina,identificador);
                int err=Integer.valueOf(ret[1]);
                if(!ret[0].equalsIgnoreCase("bien")){
                    String bla;
                    try{
                        bla=utiles.imprimir.errorSQL(err);
                    }catch(Exception e){
                        bla=ret[0];
                    }
                    mensaje("Hubo un error al eliminar la cuenta\n"+bla);
                }else{
                    javax.swing.JOptionPane.showMessageDialog( this,"Cuenta Eliminada con Exito",
                            "Informacion de la transaccion",javax.swing.JOptionPane.INFORMATION_MESSAGE);
                }
                busquedatrabajador();
            }catch(Exception efghi){
                mensaje("Error RMI\n"+efghi.toString());
            }
            
        }
    }//GEN-LAST:event_jbEliminarActionPerformed
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbBuscar;
    private javax.swing.JButton jbCancelar;
    private javax.swing.JButton jbEliminar;
    private javax.swing.JButton jbGuardar;
    private javax.swing.JButton jbImprimir;
    private javax.swing.JButton jbSalir;
    private javax.swing.JComboBox jcboBanco;
    private javax.swing.JComboBox jcboTipoCuenta;
    private javax.swing.JComboBox jcboTipoMoneda;
    private javax.swing.JCheckBox jchkCts;
    private javax.swing.JLabel jlBanco;
    private javax.swing.JLabel jlNumCuenta;
    private javax.swing.JLabel jlTipoCuenta;
    private javax.swing.JLabel jlTipoMoneda;
    private javax.swing.JLabel jlTraba;
    private javax.swing.JLabel jlTrabajador;
    private javax.swing.JPopupMenu jpmNombres;
    private javax.swing.JRadioButton jrbCodigo;
    private javax.swing.JRadioButton jrbNombre;
    private javax.swing.JTable jtCuentas;
    private javax.swing.JTextField jtfCodigo;
    private javax.swing.JTextField jtfNumCuenta;
    // End of variables declaration//GEN-END:variables
    
}
